<?php

class Card {
  /** @var integer */
  public $id;
  /** @var integer */
  public $rank;
  /** @var integer */
  public $suit;
  /** @var string */
  public $name;
  /** @var integer */
  public $value;
  /** @var integer */
  public $order;
  /** @var boolean */
  public $status;
  
  const STATUS_PRIVATE = 0;
  const STATUS_PUBLIC = 1;
  
  const CARD_SEVEN = '7';
  const CARD_EIGHT = '8';
  const CARD_NINE  = '9';
  const CARD_TEN   = '10';
  const CARD_JACK  = 'J';
  const CARD_QUEEN = 'Q';
  const CARD_KING  = 'K';
  const CARD_ACE   = 'A';

  const BELOT_SMALL_DECK = 24;
  const BELOT_BIG_DECK   = 32;
  
  public static $SUIT_NAMES = array(
    'spades', 'hearts', 'diamonds', 'clubs'  
  );
  
  public static $SUIT_TITLES = array (
    'spades'   => 'Spades',
    'hearts'   => 'Hearts',
    'diamonds' => 'Diamonds',
    'clubs'    => 'Clubs'
  );
  
  public static $CARD_NAMES = array (
    'seven', 'eight', 'nine', 'ten', 'jack', 'queen', 'king', 'ace'
  );
  
  public static $CARD_TITLES = array (
    'seven' => 'Seven',
    'eight' => 'Eight',
    'nine'  => 'Nine',
    'ten'   => 'Ten',
    'jack'  => 'Jack',
    'queen' => 'Queen',
    'king'  => 'King',
    'ace'   => 'Ace'
  );
  
  public static $CARD_VALUES = array (
    'seven' => 0,
    'eight' => 0,
    'nine'  => 0,
    'ten'   => 10,
    'jack'  => 2,
    'queen' => 3,
    'king'  => 4,
    'ace'   => 11
  );
  
  public static $TRUMP_CARD_VALUES = array(
    'seven' => 0,
    'eight' => 0,
    'nine'  => 14,
    'ten'   => 10,
    'jack'  => 20,
    'queen' => 3,
    'king'  => 4,
    'ace'   => 11 
  );


  public function __construct($rank, $suit)
  {
    $this->rank = $rank;
    $this->suit = $suit;
    $this->status = self::STATUS_PUBLIC;
  }

  public static function GetDeck($isSmallDeck = false)
  {
    $deck = array();
    $cardsNames = self::$CARD_NAMES;
    $id = 0;

    if ($isSmallDeck)
      $cardsNames = array_diff($cardsNames, array('seven', 'eight'));
    
    foreach($cardsNames as $cardName)
    {
      foreach(self::$SUIT_NAMES as $suit)
      {
        $card = new Card($cardName, $suit);

        $card->id    = $id++;
        $card->name  = self::$CARD_TITLES[$cardName];
        $card->value = self::$CARD_VALUES[$cardName];
        $deck[]      = $card;
      }
    }
    
    return $deck;
  }
  
  public static function GetShuffledDeck($isSmallDeck = false)
  {
    $deck = Card::GetDeck($isSmallDeck);
    shuffle($deck);
    $order = 0;
    foreach($deck as $card)
      $card->order = $order++;
    
    return $deck;
  }

}

?>
